/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.PassengerInfo;
import com.sasis.dao.PassengerInfoDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class PassengerInfoDaoiBatis extends BaseDaoiBATIS implements PassengerInfoDao {

    /**
     * @see com.sasis.dao.PassengerInfoDao#getPassengerInfos(com.sasis.model.PassengerInfo)
     */
    public List getPassengerInfos(final PassengerInfo passengerInfo) {
          return getSqlMapClientTemplate().queryForList("getPassengerInfos", passengerInfo);
    }

    /**
     * @see com.sasis.dao.PassengerInfoDao#getPassengerInfo(Integer id)
     */
    public PassengerInfo getPassengerInfo(Integer id) {
        PassengerInfo passengerInfo = (PassengerInfo) getSqlMapClientTemplate().queryForObject("getPassengerInfo", id);

        if (passengerInfo == null) {
            throw new ObjectRetrievalFailureException(PassengerInfo.class, id);
        }

        return passengerInfo;
    }

    /**
     * @see com.sasis.dao.PassengerInfoDao#savePassengerInfo(PassengerInfo passengerInfo)
     */    
    public void savePassengerInfo(final PassengerInfo passengerInfo) {
        Integer id = passengerInfo.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addPassengerInfo", passengerInfo);
        } else {
            getSqlMapClientTemplate().update("updatePassengerInfo", passengerInfo);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(PassengerInfo.class, id);
        }
    }

    /**
     * @see com.sasis.dao.PassengerInfoDao#removePassengerInfo(Integer id)
     */
    public void removePassengerInfo(PassengerInfo passengerInfo) {
        getSqlMapClientTemplate().update("deletePassengerInfo",  passengerInfo);
    }
}
